package com.example.demo.DAO;

import com.example.demo.Entity.Statistics;
import com.example.demo.Entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository()
public interface StatisticsDao {
    /******** 查询所有账务记录 *********/
    @Select("select * from statistics")
    List<Statistics> findAll();

    /******** 通过时间查询ID *********/
    @Select("select _id from statistics where date = #{date}")
    String findID(@Param("date")String date);

    /******** 通过ID查询全部内容 *********/
    @Select("select * from statistics where _id = #{_id}")
    Statistics findByID(@Param("_id")String _id);

    /******** 模糊查询账务 *********/
    @Select("select * from statistics where concat(_id,date,company,department," +
            "area,typeOne,typeTwo,financialFocus,typeFour,typeFive) like '%${query}%'")
    List<Statistics> fuzzyQuery(@Param("query") String query);

    /**********删除账务记录*************/
    @Delete("delete from statistics where _id = #{deleteId}")
    Integer deleteStatistics(@Param("deleteId") Integer deleteId);
    /**********添加账务记录*************/
    @Insert("insert into statistics(date,company,department,area,typeOne,typeTwo," +
            "financialFocus,typeFour,typeFive,typeSix,number,price," +
            "totalPrice,specs,remarks) values(#{date},#{company},#{department},#{area}," +
            "#{typeOne},#{typeTwo},#{financialFocus},#{typeFour},#{typeFive},#{typeSix},#{number}," +
            "#{price},#{totalPrice},#{specs},#{remarks})")
    void addStatistics(Statistics s);

    /**********修改账务记录*************/
    @Update("UPDATE statistics SET date = #{date},company = #{company},department = #{department},area = #{area} ," +
            "typeOne = #{typeOne},typeTwo = #{typeTwo},financialFocus = #{financialFocus},typeFour = #{typeFour},typeFive = #{typeFive}" +
            ",typeSix = #{typeSix},number = #{number},price = #{price},totalPrice = #{totalPrice},specs = #{specs},remarks = #{remarks}" +
            " where _id = #{_id}")
    Integer updateStatistics(Statistics statistics);


    /******** 统计每个月的开支 *********/
    @Select("select totalPrice from statistics where concat(date) like '%${query}%'")
    List<Statistics> drawLineChart(@Param("query") String query);

}
